using System.Data.Linq;
using System.Data.Linq.Mapping;
using Magiq.Support;

namespace Magiq.Sql.Support
{
    public class EntitySetAdapter
    {
        public EntitySetAdapter(object objectThatShouldBeAnEntitySet)
        {
            var source = objectThatShouldBeAnEntitySet.Field("source");
            Instance = source.Field("instance");
            var factory = source.Field("factory");
            Member = factory.Field<MetaDataMember>("member");
            DataContext = factory.Field("services")
                .Property<DataContext>("Context");
        }

        public object Instance { get; private set; }
        public DataContext DataContext { get; private set; }
        public MetaDataMember Member { get; private set; }
    }
}